package com.antrain.core;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 用来封装和存储映射信息
 */
public class Mapper {
    // 实体类名
    private String className;
    // 实体类对应的表名
    private String tableName;
    // 对应的主键
    private Map<String,String> idMapper = new HashMap<String,String>();
    // 实体类属性与表的字段对应关系
    private Map<String,String> propMapper = new HashMap<String,String>();


    public Mapper() {
    }

    public Mapper(String className, String tableName, Map<String,String> idMapper, Map<String,String> propMapper) {
        this.className = className;
        this.tableName = tableName;
        this.idMapper = idMapper;
        this.propMapper = propMapper;
    }

    public String getClassName() {
        return this.className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getTableName() {
        return this.tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public Map<String,String> getIdMapper() {
        return this.idMapper;
    }

    public void setIdMapper(Map<String,String> idMapper) {
        this.idMapper = idMapper;
    }

    public Map<String,String> getPropMapper() {
        return this.propMapper;
    }

    public void setPropMapper(Map<String,String> propMapper) {
        this.propMapper = propMapper;
    }

    public Mapper className(String className) {
        this.className = className;
        return this;
    }

    public Mapper tableName(String tableName) {
        this.tableName = tableName;
        return this;
    }

    public Mapper idMapper(Map<String,String> idMapper) {
        this.idMapper = idMapper;
        return this;
    }

    public Mapper propMapper(Map<String,String> propMapper) {
        this.propMapper = propMapper;
        return this;
    }

    @Override
    public boolean equals(Object o) {
        if (o == this)
            return true;
        if (!(o instanceof Mapper)) {
            return false;
        }
        Mapper mapper = (Mapper) o;
        return Objects.equals(className, mapper.className) && Objects.equals(tableName, mapper.tableName) && Objects.equals(idMapper, mapper.idMapper) && Objects.equals(propMapper, mapper.propMapper);
    }

    @Override
    public int hashCode() {
        return Objects.hash(className, tableName, idMapper, propMapper);
    }

    @Override
    public String toString() {
        return "{" +
            " className='" + getClassName() + "'" +
            ", tableName='" + getTableName() + "'" +
            ", idMapper='" + getIdMapper() + "'" +
            ", propMapper='" + getPropMapper() + "'" +
            "}";
    }

}